package com.schoolcloud.front.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.schoolcloud.common.model.PageDTO;
import com.schoolcloud.front.entity.NotificationTemplates;
import com.schoolcloud.front.query.NotificationTemplateQuery;
import com.schoolcloud.front.service.NotificationTemplatesService;
import com.schoolcloud.front.mapper.NotificationTemplatesMapper;
import com.schoolcolud.daomybatisplus.dto.MpPageUtil;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @author hongmizfb
 * @description 针对表【notification_templates(通知模板表)】的数据库操作Service实现
 * @createDate 2025-08-16 16:48:29
 */
@Service
public class NotificationTemplatesServiceImpl extends ServiceImpl<NotificationTemplatesMapper, NotificationTemplates>
        implements NotificationTemplatesService {

    @Override
    public boolean saveNotificationTemplate(NotificationTemplates notificationTemplate) {
        notificationTemplate.setCreateTime(LocalDateTime.now());
        return save(notificationTemplate);
    }

    @Override
    public PageDTO<NotificationTemplates> getNotificationTemplatePage(NotificationTemplateQuery query) {
        Page<NotificationTemplates> page = lambdaQuery().page(query.toMpPage());
        return MpPageUtil.of(page, NotificationTemplates.class);
    }

    @Override
    public NotificationTemplates getByType(String type) {
        return lambdaQuery().eq(NotificationTemplates::getType, type).one();
    }
}




